package quicksync

import "context"

type SyncStepType int

var (
	SyncStepTypeOne   SyncStepType = 1
	SyncStepTypeTwo   SyncStepType = 2
	SyncStepTypeThree SyncStepType = 3
	SyncStepTypeFour  SyncStepType = 4

	StepTypes = []SyncStepType{
		SyncStepTypeOne,
		SyncStepTypeTwo,
		SyncStepTypeThree,
		SyncStepTypeFour,
	}
)
var (
	syncServices []SyncService
	syncTypes    []string
	syncTypesZh  []string //用于查询语句下拉框关联
)

func GetSyncTypesZh() []string {
	return syncTypesZh
}
func GetSyncTypes() []string {
	return syncTypes
}

type SyncService interface {
	GetName() string
	GetNameZh() string
	GetStep() SyncStepType
	GetQueue() *SyncQueue
	GetEntity() interface{}
	ValidateSql(string) error
	GetSubType() string
	WantRun() bool
	WantSql() bool
	SyncFunc(context.Context, string, string) error
}

func RegSyncService(srv SyncService) {
	syncTypes = append(syncTypes, srv.GetName())
	if srv.WantSql() {
		syncTypesZh = append(syncTypesZh, srv.GetNameZh())
	}
	syncServices = append(syncServices, srv)
}
func GetSyncService(syncType string) SyncService {
	for _, srv := range syncServices {
		if srv.GetName() == syncType {
			return srv
		}
	}
	return nil
}
func GetServiceZh(syncTypeZh string) SyncService {
	for _, srv := range syncServices {
		if srv.GetNameZh() == syncTypeZh {
			return srv
		}
	}
	return nil
}
